//
//  ZGrantListCell.m
//  DistributorAB
//
//  Created by LZY on 2019/10/15.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZGrantListCell.h"
@interface ZGrantListCell ()
@property (nonatomic, strong) UILabel *lblDate;//申请日期
@property (nonatomic, strong) UILabel *lblState;//申请状态
@property (nonatomic, strong) UILabel *lblCategory;//配件品类
@property (nonatomic, strong) UILabel *lblName;//配件名称
@property (nonatomic, strong) UILabel *lblPay;//赔付金额
@end

@implementation ZGrantListCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupViewAction];
    }
    return self;
}
#pragma mark - 界面布局
- (void)setupViewAction{
    self.contentView.backgroundColor = kColorWithHex(0xf2f2f2);
    
    UIView *viewBg = [[UIView alloc] initWithFrame:CGRectMake(0, 10, kScreen_Width, 163)];
    viewBg.backgroundColor = kColorWithHex(0xffffff);
    [self.contentView addSubview:viewBg];
    
    _lblDate = [UILabel new];
    _lblDate.font = [UIFont systemFontOfSize:12];
    _lblDate.textColor = kColorWithHex(0x999999);
    [viewBg addSubview:_lblDate];
    [_lblDate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(viewBg.mas_leading).offset(16);
        make.top.equalTo(viewBg.mas_top).offset(9);
        make.height.mas_equalTo(17);
    }];
    
    _lblState = [UILabel new];
    _lblState.font = [UIFont systemFontOfSize:11];
    _lblState.textColor = kColorWithHex(0xf88b1f);
    [viewBg addSubview:_lblState];
    [_lblState mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(viewBg.mas_trailing).offset(-16);
        make.centerY.equalTo(self.lblDate.mas_centerY);
        make.height.mas_equalTo(17);
    }];
    
    UILabel *lblNoticeCategory = [UILabel new];
    if (AGENT_LEVEL==1) {
         lblNoticeCategory.text = @"所在区域:";
    }else
    {
         lblNoticeCategory.text = @"配件品类:";
    }
   
    lblNoticeCategory.font = [UIFont systemFontOfSize:14];
    lblNoticeCategory.textColor = kColorWithHex(0x666666);
    [viewBg addSubview:lblNoticeCategory];
    [lblNoticeCategory mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.lblDate.mas_leading);
        make.top.equalTo(self.lblDate.mas_bottom).offset(8);
        make.height.mas_equalTo(20);
    }];
    
    _lblCategory = [UILabel new];
    _lblCategory.font = [UIFont boldSystemFontOfSize:14];
    _lblCategory.textColor = kColorWithHex(0x333333);
    [viewBg addSubview:_lblCategory];
    [_lblCategory mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lblNoticeCategory.mas_centerY);
        make.leading.equalTo(lblNoticeCategory.mas_trailing).offset(10);
        make.height.mas_equalTo(20);
    }];
    
    UILabel *lblNoticeName = [UILabel new];
    lblNoticeName.text = @"配件名称:";
    lblNoticeName.font = [UIFont systemFontOfSize:14];
    lblNoticeName.textColor = kColorWithHex(0x666666);
    [viewBg addSubview:lblNoticeName];
    [lblNoticeName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.lblDate.mas_leading);
        make.top.equalTo(lblNoticeCategory.mas_bottom).offset(6);
        make.height.mas_equalTo(20);
    }];
    
    _lblName = [UILabel new];
    _lblName.font = [UIFont boldSystemFontOfSize:14];
    _lblName.textColor = kColorWithHex(0x333333);
    [viewBg addSubview:_lblName];
    [_lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lblNoticeName.mas_centerY);
        make.leading.equalTo(lblNoticeName.mas_trailing).offset(10);
        make.height.mas_equalTo(20);
    }];
    
    UILabel *lblNoticePay = [UILabel new];
    lblNoticePay.text = @"补贴工时费:";
    lblNoticePay.font = [UIFont systemFontOfSize:14];
    lblNoticePay.textColor = kColorWithHex(0x666666);
    [viewBg addSubview:lblNoticePay];
    [lblNoticePay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.lblDate.mas_leading);
        make.top.equalTo(lblNoticeName.mas_bottom).offset(6);
        make.height.mas_equalTo(20);
    }];
    
    _lblPay = [UILabel new];
    _lblPay.font = [UIFont boldSystemFontOfSize:14];
    _lblPay.textColor = kColorWithHex(0x333333);
    [viewBg addSubview:_lblPay];
    [_lblPay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lblNoticePay.mas_centerY);
        make.leading.equalTo(lblNoticePay.mas_trailing).offset(10);
        make.height.mas_equalTo(20);
    }];
    
    UIView *viewLine = [UIView new];
    viewLine.backgroundColor = kColorWithHex(0xf2f2f2);
    [viewBg addSubview:viewLine];
    [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(viewBg);
        make.top.equalTo(lblNoticePay.mas_bottom).offset(10);
        make.height.mas_equalTo(1);
    }];
    
    UILabel *lblNoticeCheck = [UILabel new];
    lblNoticeCheck.text = @"查看详情";
    lblNoticeCheck.font = [UIFont boldSystemFontOfSize:14];
    lblNoticeCheck.textColor = kColorWithHex(0x666666);
    [viewBg addSubview:lblNoticeCheck];
    [lblNoticeCheck mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.lblDate.mas_leading);
        make.top.equalTo(viewLine.mas_bottom).offset(12);
        make.height.mas_equalTo(20);
    }];
    
    UIImageView *ivArrow = [UIImageView new];
    ivArrow.image = imgname(@"arrow_right_icon");
    [viewBg addSubview:ivArrow];
    [ivArrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lblNoticeCheck.mas_centerY);
        make.trailing.equalTo(viewBg.mas_trailing).offset(-16);
        make.size.mas_equalTo(CGSizeMake(8, 16));
    }];
    
}
#pragma mark - 数据更新
- (void)setGrantModel:(ZGrantListModel *)grantModel{
    if (grantModel) {
        _grantModel = grantModel;
        _lblDate.text = grantModel.createTime;
        _lblName.text = grantModel.parts_name;
        _lblPay.text = [NSString stringWithFormat:@"￥%@",grantModel.compensationPrice];
        if (AGENT_LEVEL == 1) {
            
            //省级
            //所在区域
            _lblCategory.text = [NSString stringWithFormat:@"%@",grantModel.area_name];

            if ([grantModel.state isEqualToString:@"1"]) {
                _lblState.text = @"未审核";
            }else{
                _lblState.text = @"已审核";
            }
        }else{
            //市县级
            //配件品类
            _lblCategory.text = [NSString stringWithFormat:@"%@ %@",grantModel.firstName,grantModel.secondName];
            
            //状态（1未审核 2省级未通过 3省级已通过 4平台未通过 5平台已通过 6已到账）
            if ([grantModel.state isEqualToString:@"1"]) {
                _lblState.text = @"未审核";
            }
            else if ([grantModel.state isEqualToString:@"2"]){
                _lblState.text = @"省级未通过";
            }
            else if ([grantModel.state isEqualToString:@"3"]){
                _lblState.text = @"省级已通过";
            }
            else if ([grantModel.state isEqualToString:@"4"]){
                _lblState.text = @"平台未通过";
            }
            else if ([grantModel.state isEqualToString:@"5"]){
                _lblState.text = @"平台已通过";
            }else if ([grantModel.state isEqualToString:@"6"]){
                _lblState.text = @"已到账";
            }
            
        }
    }
}
+ (CGFloat)cellHeight{
    return 173.0;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
